/*----------------------------------------------------------------------------------------------
*
* This file is ArcSoft's property. It contains ArcSoft's trade secret, proprietary and 		
* confidential information. 
* 
* The information and code contained in this file is only for authorized ArcSoft employees 
* to design, create, modify, or review.
* 
* DO NOT DISTRIBUTE, DO NOT DUPLICATE OR TRANSMIT IN ANY FORM WITHOUT PROPER AUTHORIZATION.
* 
* If you are not an intended recipient of this file, you must not copy, distribute, modify, 
* or take any action in reliance on it. 
* 
* If you have received this file in error, please immediately notify ArcSoft and 
* permanently delete the original and any copy of any file and any printout thereof.
*
*-------------------------------------------------------------------------------------------------*/

package  summitsoft.android.hiwifi.base;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public final class ResolutionAdapter
{
	/*
	 * for private data
	 */
	private static 			Display mDisplay								= null;
	private static 			DisplayMetrics mDisplayMetrics					= null;
	private static 			int mDisplayWidth								= 0;
	private static 			int	mDisplayHeight								= 0;
	private static			int	mDisplayLogPixelSX							= 0;
	private static  		int	mDisplayLogPixelSY							= 0;
	
	private static 	final	int	STANDARD_LOGPIXELSX							= 166;
	private static 	final	int	STANDARD_LOGPIXELSY							= 167;
	private static  final 	int DEVICE_RESTYPE_START						= 0;
	public 	static 	final	int DEVICE_RESTYPE_HVGA							= DEVICE_RESTYPE_START + 1;
	public  static  final	int DEVICE_RESTYPE_WVGA							= DEVICE_RESTYPE_START + 2;
	
	/*
	 * for constant functions
	 */	
	public static void initResolutionAdapter(Context context)
	{
		mDisplay = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

		if (null == mDisplayMetrics)
		{
			mDisplayMetrics = new DisplayMetrics();
		}
		mDisplay.getMetrics(mDisplayMetrics);
		
		mDisplayLogPixelSX 	= (int)(mDisplayMetrics.xdpi + 0.5);
		
		mDisplayLogPixelSY	= (int)(mDisplayMetrics.ydpi + 0.5);
		
		mDisplayWidth = mDisplay.getWidth();
		
		mDisplayHeight	= mDisplay.getHeight();
	}
	public static boolean isScreenLandScape()
	{		
		return mDisplay.getWidth() > mDisplay.getHeight();
	}
	public static int getDisplayWidth()
	{
		return mDisplay.getWidth();
	}
	public static int getDisplayHeight()
	{
		return mDisplay.getHeight();
	}
	public static int getScaleX(int xValue)
	{
		return (xValue * mDisplayLogPixelSX + (STANDARD_LOGPIXELSX >> 1)) / STANDARD_LOGPIXELSX;		
	}
	public static int getScaleY(int yValue)
	{
		return (yValue * mDisplayLogPixelSY + (STANDARD_LOGPIXELSY >> 1)) / STANDARD_LOGPIXELSY;
	}
	public static int getDeviceResType()
	{
		int nWidth = Math.min(mDisplayWidth, mDisplayHeight);
		int nHeight = Math.max(mDisplayWidth, mDisplayHeight);
		
		if (320 == nWidth && 480 == nHeight)
		{
			return DEVICE_RESTYPE_HVGA;
		}
		else if (480 == nWidth && 800 == nHeight)
		{
			return DEVICE_RESTYPE_WVGA;
		}
		
		return DEVICE_RESTYPE_HVGA;
	}
}